﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using com.codebump;

public partial class IBC_IBC_Outbound : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString.HasKeys())
            {
                if (Request.QueryString["listid"] != String.Empty)
                    Session["listid"] = Request.QueryString["listid"];
                else
                    Session["listid"] = 1;


                if (Request.QueryString["dnis"] != null)
                {
                    Session["dnis"] = Request.QueryString["dnis"];
                }
                else
                {
                    Session["dnis"] = "9999999999";
                }

                Session["servername"] = Request.QueryString["servername"];
                Session["projectname"] = Request.QueryString["projectname"];
                Session["campaignname"] = Request.QueryString["campaignname"];
                Session["agentid"] = Request.QueryString["agentid"];
                Session["agentfirst"] = Request.QueryString["agentfirst"];
                Session["agentlast"] = Request.QueryString["agentlast"];
                Session["ani"] = Request.QueryString["ani"];
                Session["commit"] = false;

                Session["App"] = new DataAccess();              

                lblrConfirmationNum.Text = Session["listid"].ToString();
                //ValidateIBListID();
            }
            //The session variables are requested in the master page currently using the following syntax: Session["servername"] = Request.QueryString["servername"];
            //The page is loaded before the master page so if the code isn't in a control, it will currently error out.
            //((DataAccess)Session["App"]).ConnectInbound(Session["servername"].ToString(), Session["projectname"].ToString(), Session["campaignname"].ToString(), Session["dnis"].ToString(), Session["listid"].ToString());

            Session["Oven"] = "";
            Session["ERK"] = 0;
            Session["SPK"] = 0;
            Session["CInfo"] = false;
            lblAgentName.Text = (Session["agentfirst"].ToString() + " " + Session["agentlast"].ToString()).Trim() + " ";
            WebWizard.ActiveStepIndex = 0;
            if (string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("webusercode").ToString()))
            {
                ((DataAccess)Session["App"]).PutCallData("webusercode", "J5");
            }
            ((DataAccess)Session["App"]).PutCallData("Calldate", DateTime.Now.ToString());
            ((DataAccess)Session["App"]).PutCallData("IsOutbound", "true");
            ((DataAccess)Session["App"]).CommitCallData();

            prepopulateFields();
            ////the following block of code specifies the years for cc expiration date validation and adds that to the error message (dynamically)
            //int yearval;
            //yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
            //rvExpYear.MinimumValue = yearval.ToString();
            //rvExpYear.ErrorMessage += "(" + yearval.ToString() + " - ";
            //rvExpYear.MaximumValue = (yearval + 10).ToString();
            //rvExpYear.ErrorMessage += (yearval + 10).ToString() + ")";
        }
        else
        {
            if (cbMini.Checked || cbRefurb.Checked)
            {
                btnSave.Visible = false;
            }
            else
            {
                btnSave.Visible = true;
            }
        }


    }
    protected void prepopulateFields()
    {
        bool bHasShipInfo = false;
        bHasShipInfo =  !(string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("ShipAddress1"))  &&
                        string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("ShipAddress2")) &&
                        string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("ShipZip")));

        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("FirstName")))
        {
            tbFirstName.Text = ((DataAccess)Session["App"]).GetCallData("FirstName");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("LastName")))
        {
            tbLastName.Text = ((DataAccess)Session["App"]).GetCallData("LastName");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("Address1")))
        {
            tbAddr.Text = ((DataAccess)Session["App"]).GetCallData("Address1");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("Address2")))
        {
            tbAddr2.Text = ((DataAccess)Session["App"]).GetCallData("Address2");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("Zip")))
        {
            tbZip.Text = ((DataAccess)Session["App"]).GetCallData("Zip");
            btnSearchZip_Click(null, null); //run logic for getting city info from zip
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("PrimaryPhone")))
        {
            tbPhone.Text = ((DataAccess)Session["App"]).GetCallData("PrimaryPhone");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("Email")))
        {
            tbEmail.Text = ((DataAccess)Session["App"]).GetCallData("Email");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("ShipAddress1")))
        {
            tbShipAddr.Text = ((DataAccess)Session["App"]).GetCallData("ShipAddress1");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("ShipAddress2")))
        {
            tbShipaddr2.Text = ((DataAccess)Session["App"]).GetCallData("ShipAddress2");
        }
        if (!string.IsNullOrEmpty(((DataAccess)Session["App"]).GetCallData("ShipZip")))
        {
            tbShipZip.Text = ((DataAccess)Session["App"]).GetCallData("ShipZip");
            btnShipSearchZip_Click(null, null);
        }
        if (bHasShipInfo)
        {
            cbShipping.Checked = true;
            cbShipping_CheckedChanged(null, null);
        }
        
        
    }
    //POST LOGIC - For Step or Start pages
    //Add if statements as you add pages
    //For Next and Finish pages it is best to use the index in the if statements as below
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
/////////////////////////Main Offer Page post-logic/////////////////////////////
        if (page == WebWizard.WizardSteps.IndexOf(this.MainOffer))
        {
            if (ddlMainProd.SelectedIndex > 0)
            {
                Page.SetFocus(ddlMainProd);
                Session["commit"] = true;
                
                if (ddlMainProd.SelectedIndex == 1 && !cbMini.Checked)
                {
                    pnlAddtlOvens.Visible = true;                   
                }
                else
                {
                    pnlAddtlOvens.Visible = false;
                    ddlAddtlOvenQty.SelectedIndex = 0;
                } 
                ddlAddtlOvenQty_SelectedIndexChanged(null, null);   //calling this will fill the dropdown lists with applicable quantities
            }
            else
            {
                ddlAddtlOvenQty.SelectedIndex = 0;
                //WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.MainOffer);//covered by pre-logic
                Session["commit"] = false;
            }
            return;
        }
////////////////////////////Upsell Page post-logic/////////////////////////////

        if (page == WebWizard.WizardSteps.IndexOf(this.Upsells)) //post-logic for upsell pages
        {
            if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
            {
                pnlrOnePayTotal.Visible = true;
                pnlrMultiPayTotal.Visible = false;
            }
            else
            {
                pnlrMultiPayTotal.Visible = true;
                pnlrOnePayTotal.Visible = false;
            }
            updateRecapTable();
            return;
            
        }

/////////////////////////////Recap Page post-logic/////////////////////////////
        if (page == WebWizard.WizardSteps.IndexOf(this.Recap))
        {
            if (ddlPaymentType.SelectedValue.ToString() == "EC")
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            }
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }
    }

    //POST LOGIC for disposition pages
    //this is for pages that contain a disposition button
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Recap))
        {

            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }


    }

    //PRE-LOGIC
    //Add if statements as needed for post-logic
    //You can use the Step ID name instead of the index as used in Next and Finish logic.
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {
        if (WebWizard.ActiveStep.Title.ToString() == "Upsells")
        {
            if (ddlMainProd.SelectedIndex <= 0)
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.MainOffer);
            }
        }
        if (WebWizard.ActiveStep.Title.ToString() == "Recap")
        {
            if (pnlrOnePayTotal.Visible)
            {
                lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");

                if (cbfourpay.Checked)
                {
                    lblrPmtNumber.Text = "3";
                    lblrPmtNumber0.Text = "3";
                }
                else
                {
                    lblrPmtNumber.Text = "2";
                    lblrPmtNumber0.Text = "2";
                }
                //lblAmount.Text = lblrOnePayTotal.Text;
                
            }
            else
            {
                lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
                lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");

                if (cbfourpay.Checked)
                {
                    lblrPmtNumber.Text = "3";
                    lblrPmtNumber0.Text = "3";
                }
                else
                {
                    lblrPmtNumber.Text = "2";
                    lblrPmtNumber0.Text = "2";
                }
                //lblAmount.Text = lblrMultiPayTotal1st.Text;
            }
            if (ddlPaymentType.SelectedItem.Value == "EC")
            {
                ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
                ((DataAccess)Session["App"]).PutCallData("RecurringTotal", "0");
            }
            else
            {
                if (cbOnePay.Checked)
                {
                    ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
                    ((DataAccess)Session["App"]).PutCallData("RecurringTotal", "0");
                }
                else
                {
                    ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrMultiPayTotal1st.Text);
                    ((DataAccess)Session["App"]).PutCallData("RecurringTotal", lblrMultiPayTotal2.Text);
                }
            }
            if (ddlPaymentType.SelectedItem.Value == "EC" && GetOrderTotalPerItemShipping() > 300.00)//Convert.ToDouble(lblrOnePayTotal.Text) > 300.00)
            {
                lblrOver300.Visible = true;
                Page.SetFocus(lblrOver300);
            }
        }
        if (WebWizard.ActiveStep.Title.ToString() == "Disposition")
        {

            if ((bool)Session["commit"] && (bool)Session["CInfo"])
            {
                if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
                {
                    ((DataAccess)Session["App"]).PutCallData("NumberOfRecurringPayments","0");
                }
                else if (cbfourpay.Checked)
                {
                    ((DataAccess)Session["App"]).PutCallData("NumberOfRecurringPayments", "3");
                }
                else
                {
                    ((DataAccess)Session["App"]).PutCallData("NumberOfRecurringPayments", "2");
                }
                pnlDispoConfirm.Visible = false;
                ((DataAccess)Session["App"]).PutCallData("webtransfer", "");
                ((DataAccess)Session["App"]).PutCallData("webusercode", "I0");
                ((DataAccess)Session["App"]).CommitOrder();
                ((DataAccess)Session["App"]).CommitCallData();
                Response.Redirect("../DispositionComplete.aspx");
            }
            else if (!(bool)Session["commit"])
            {
                pnlDispoNonSale.Visible = true;
                pnlDispoConfirm.Visible = true;
            }
            else if (!(bool)Session["CInfo"])
            {
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Recap);
                lblCInfoSubmitted.Visible = true;
            }
            else
            {
            }
            return;
        }
        else
        {
        }

    }

    //protected void rblTwistMix_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    Page.SetFocus(ddlMainTwistMixQty);
    //    if (rblTwistMix.SelectedValue == "TwisterDownsell")
    //    {
    //        lblTwistMix.Text = "How many additional Twisters would you like?";
    //        pnlTwister.Visible = true;
    //    }
    //    else
    //    {
    //        lblTwistMix.Text = "How many additional sets of the Party Mixer and Twister would you like?";
    //        pnlTwister.Visible = false;
    //    }
    //}
    protected void btnPizzaDownsell_Click(object sender, EventArgs e)
    {
        Page.SetFocus(cbPKDown);
        pnlPizzaDownsell.Visible = true;
        btnPizzaDownsell.Visible = false;
        //Session["Pizza"] = "downsell";
    }
    
    protected void btnExtRingReb_Click(object sender, EventArgs e)
    {

        if (pnlExtenderRingDownsell1.Visible)
        {
            pnlExtenderRingDownsell1.Visible = false;
            pnlExtenderRingDownsell2.Visible = true;
            btnExtRingReb.Visible = false;
            //cbERKDown1.Checked = false;
            //Session["ERKDownsell"] = "Downsell2";
            Page.SetFocus(ddlExtenderRingQty);
        }
        else
        {
            pnlExtenderRingDownsell1.Visible = true;
            btnExtRingReb.Text = "Next Rebuttal";
            //Session["ERKDownsell"] = "Downsell1";
            Page.SetFocus(btnExtRingReb);
        }
    }
    protected void btnMainDwn_Click(object sender, EventArgs e)
    {
        if (pnlRefurb.Visible)
        {
            pnlMini.Visible = true;
            btnMainDwn.Visible = false;
            Page.SetFocus(ddlMainProd);
        }
        else if (pnlfourpay.Visible)
        {
            pnlRefurb.Visible = true;
            //pnlfourpay.Visible = false;
            //cbfourpay.Checked = false;
            Page.SetFocus(btnMainDwn);
        }
        else
        {
            pnlfourpay.Visible = true;
            btnMainDwn.Text = "Next Downsell";
            Page.SetFocus(btnMainDwn);
        }
    }
    protected void rbl24Hour_SelectedIndexChanged(object sender, EventArgs e)
    {
        Page.SetFocus(btnFAQ);
        if (rbl24Hour.SelectedValue == "No")
        {
            pnlRushShip.Visible = true;
        }
        else
        {
            pnlRushShip.Visible = false;
            cbRushShip.Checked = false;
        }
    }
    protected void btnBlackReb_Click(object sender, EventArgs e)
    {
        Page.SetFocus(cbBlackOvens);
        pnlBlackReb.Visible = true;
        btnBlackReb.Visible = false;
        //Session["BlackReb"] = true;
    }

    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        lblError.Text = "";

        bool bCustValid = false;
        bool ccCheck = false;
        bool ecCheck = false;
        bool bShipValid = false;
        bool bShowBInfo = false;
        int yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
        //int result;

        bCustValid = !(string.IsNullOrEmpty(tbFirstName.Text) ||
            string.IsNullOrEmpty(tbLastName.Text) ||
            string.IsNullOrEmpty(tbAddr.Text) ||
            (tbAddr.Text == "PO BOX ") ||
            string.IsNullOrEmpty(tbZip.Text) ||
            string.IsNullOrEmpty(ddlCity.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlCountry.SelectedItem.Text)) &&
            (ddlCity.SelectedIndex > 0);

        if (tbExpDate.Text.Length == 4)
        {
            ccCheck = !(string.IsNullOrEmpty(ddlCardType.SelectedItem.Text) ||
                string.IsNullOrEmpty(tbCCNumber.Text) ||
                //string.IsNullOrEmpty(tbCCV.Text) ||
                string.IsNullOrEmpty(tbExpDate.Text) ||
                (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) == yearval && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) < Convert.ToInt32(DateTime.Today.ToString("MM")))) &&
                (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) >= yearval) &&
                (Convert.ToInt32(tbExpDate.Text.Substring(2, 2)) <= (yearval + 10)) &&
                (Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) >= 1 && Convert.ToInt32(tbExpDate.Text.Substring(0, 2)) <= 12) &&
                (((DataAccess)Session["App"]).IsValidCC(GetCardType(ddlCardType.SelectedValue), tbCCNumber.Text)) &&
                //(System.Text.RegularExpressions.Regex.IsMatch(tbCCV.Text, @"^[\d]+$")) &&
                (System.Text.RegularExpressions.Regex.IsMatch(tbExpDate.Text, @"^[\d]+$"));
        }
        else
        {
            ccCheck = false;
        }

        ecCheck = !(string.IsNullOrEmpty(tbBankName.Text) ||
            string.IsNullOrEmpty(tbAccHolder.Text) ||
            string.IsNullOrEmpty(tbAccNum.Text) ||
            string.IsNullOrEmpty(tbRoutNum.Text) ||
            string.IsNullOrEmpty(tbCheckNum.Text)) &&
            (System.Text.RegularExpressions.Regex.IsMatch(tbAccNum.Text, @"^[\d]+$")) &&
            (System.Text.RegularExpressions.Regex.IsMatch(tbRoutNum.Text, @"^[\d]+$")) &&
            (System.Text.RegularExpressions.Regex.IsMatch(tbCheckNum.Text, @"^[\d]+$")) &&
            ((DataAccess)Session["App"]).ValidateRoutingNumber(Convert.ToInt32(tbRoutNum.Text));
        //(Int32.TryParse(tbAccNum.Text, out result)) &&
        //(Int32.TryParse(tbRoutNum.Text, out result)) &&
        //(Int32.TryParse(tbCheckNum.Text, out result));

        bShipValid = !(string.IsNullOrEmpty(tbShipAddr.Text) ||
            (tbShipAddr.Text == "PO BOX ") ||
            //string.IsNullOrEmpty(tbShipaddr2.Text) ||
            string.IsNullOrEmpty(tbShipZip.Text) ||
            string.IsNullOrEmpty(ddlShipCity.SelectedItem.Text) ||
            ddlShipState.Items.Count <= 0 ||
            string.IsNullOrEmpty(ddlShipState.SelectedItem.Text) ||
            string.IsNullOrEmpty(ddlShipCountry.SelectedItem.Text)) &&
            (ddlShipCity.SelectedIndex > 0) &&
            (tbShipZip.Text.Length >= 5) &&
            (tbShipZip.Text.Length <= 7);

        if (!cbShipping.Checked)
        {
            if (bCustValid)
            {
                switch (ddlState.SelectedItem.Text)
                {
                    case "VI":
                    case "GU":
                    case "MP":
                    case "AS":
                    case "FM":
                    case "MH":
                    case "PW":
                    case "AA":
                    case "AE":
                    case "AP":
                    case "CZ":
                    case "PI":
                    case "TT":
                    case "CM":
                        bCustValid = false;
                        lblError.Text += "Doesn't ship to US territories (PR excluded), Guam, or the Virgin Islands<br/>";
                        break;
                }
            }
        }
        else
        {
            if (bShipValid)
            {
                switch (ddlShipState.SelectedItem.Text)
                {
                    case "VI":
                    case "GU":
                    case "MP":
                    case "AS":
                    case "FM":
                    case "MH":
                    case "PW":
                    case "AA":
                    case "AE":
                    case "AP":
                    case "CZ":
                    case "PI":
                    case "TT":
                    case "CM":
                        bShipValid = false;
                        lblError.Text += "Doesn't ship to US territories (PR excluded), Guam, or the Virgin Islands<br/>";
                        break;
                }
            }
        }

        if (bCustValid)
        {
            ((DataAccess)Session["App"]).PutCallData("firstname", tbFirstName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("lastname", tbLastName.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("address1", tbAddr.Text.Replace(",", ""));
            if (!string.IsNullOrEmpty(tbAddr2.Text))
                ((DataAccess)Session["App"]).PutCallData("address2", tbAddr2.Text.Replace(",", ""));
            else
                ((DataAccess)Session["App"]).PutCallData("address2", "");
            ((DataAccess)Session["App"]).PutCallData("Zip", tbZip.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("City", ddlCity.SelectedItem.Text.Replace(",", ""));
            ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedItem.Text);
            ((DataAccess)Session["App"]).PutCallData("Country", ddlCountry.SelectedItem.Text);

            //this is what happens if the shipping info is not visible
            if (!cbShipping.Checked)
            {
                ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text.Replace(",", ""));
                if (!string.IsNullOrEmpty(tbAddr2.Text))
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text.Replace(",", ""));
                else
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                ((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlCity.SelectedItem.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedItem.Text);
                ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedItem.Text);
            }
            //this is what happens if the shipping info is visible
            else
            {
                if (bShipValid)
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text.Replace(",", ""));
                    if (!string.IsNullOrEmpty(tbShipAddr.Text))
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbShipaddr2.Text.Replace(",", ""));
                    else
                        ((DataAccess)Session["App"]).PutCallData("ShipAddress2", "");
                    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlShipCity.SelectedItem.Text.Replace(",", ""));
                    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedItem.Text);
                    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedItem.Text);
                }
                else
                {
                    lblError.Text += "Enter Valid Shipping Info<br/>";
                }
            }
        }
        //this else covers error checking
        else
        {
            if (tbAddr.Text == "PO BOX ")
            {
                lblError.Text += "Enter a PO BOX number <br/>";
            }
            else
            {
                if (ddlCity.Items.Count > 1 && ddlCity.SelectedIndex == 0)
                {
                    lblError.Text += "Select a City<br/>";
                }
                else
                {
                    lblError.Text += "Enter Valid Customer Data<br/>";
                }
            }
        }

        if ((!string.IsNullOrEmpty(tbPhone.Text)) && ((tbPhone.Text.Length != 10) || !(System.Text.RegularExpressions.Regex.Match(tbPhone.Text, @"^[1-9]\d{2}[1-9]\d{6}$").Success)))
        {
            lblError.Text += "Invalid Phone<br/>";
        }
        else
        {
            if (!string.IsNullOrEmpty(tbPhone.Text))
                ((DataAccess)Session["App"]).PutCallData("PrimaryPhone", tbPhone.Text);
        }

        if ((!string.IsNullOrEmpty(tbEmail.Text)) && !((DataAccess)Session["App"]).IsValidEmail(tbEmail.Text))
        {
            lblError.Text += "Invalid Email<br/>";
        }
        else
        {
            if (!string.IsNullOrEmpty(tbEmail.Text))
                ((DataAccess)Session["App"]).PutCallData("Email", tbEmail.Text);
        }





        if (ddlPaymentType.SelectedIndex == 1) // debit/credit
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            if (ccCheck)
            {
                ((DataAccess)Session["App"]).PutCallData("CCType", ddlCardType.SelectedItem.Value);
                ((DataAccess)Session["App"]).PutCallData("CCNumber", ((DataAccess)Session["App"]).EnryptData(tbCCNumber.Text));
                //((DataAccess)Session["App"]).PutCallData("CCV", ((DataAccess)Session["App"]).EnryptData(tbCCV.Text));
                ((DataAccess)Session["App"]).PutCallData("CCExpDate", ((DataAccess)Session["App"]).EnryptData((tbExpDate.Text.Substring(0, 2) + "/" + tbExpDate.Text.Substring(2, 2))));
                
            }
            else
            {
                lblError.Text += "Invalid Card Info<br/>";
            }
        }
        else if (ddlPaymentType.SelectedIndex == 2) // echeck
        {
            ((DataAccess)Session["App"]).PutCallData("PaymentType", ddlPaymentType.SelectedItem.Value);

            if (ecCheck)
            {
                ((DataAccess)Session["App"]).PutCallData("ECBankName", tbBankName.Text.Replace(",",""));
                ((DataAccess)Session["App"]).PutCallData("ECAccHolder", tbAccHolder.Text.Replace(",", ""));
                ((DataAccess)Session["App"]).PutCallData("ECAccNumber", tbAccNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECRoutingNumber", tbRoutNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECCheckNumber", tbCheckNum.Text);
                ((DataAccess)Session["App"]).PutCallData("ECAccType", ddlAccType.SelectedItem.Text);
            }
            else
            {
                lblError.Text += "Invalid Bank Info<br/>";
            }
        }
        else
        {
            lblError.Text += "Please select a payment method." + Environment.NewLine;
        }

        if (ddlPaymentType.SelectedValue == "EC")
        {
            pnlOnePay.Visible = false;
        }
        else
        {
            pnlOnePay.Visible = true;
        }
        if (bCustValid && (ccCheck || ecCheck))
        {
            if (!cbShipping.Checked || bShipValid)
            {
                Session["CInfo"] = true;
                lblCInfoSubmitted.Visible = false;
            }
            else
            {
                Session["CInfo"] = false;
                lblCInfoSubmitted.Visible = true;
            }
        }
        else
        {
            Session["CInfo"] = false;
            lblCInfoSubmitted.Visible = true;
        }
        if (pnlWizard.Visible)
        {
            updateRecapTable();

            lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
            lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
            lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");
                
            //buildOrder();

            ////binds the products to the listbox

            ////BoundField priceField = GridView1.Columns[0] as BoundField;
            ////priceField.DataFormatString = "{0:c}";
            ////priceField.HtmlEncode = false;
            //BoundField desc = new BoundField();
            //desc.DataField = "ProductDesc";
            //desc.HeaderText = "Product Description";
            //desc.HtmlEncode = false;
            //BoundField Price = new BoundField();
            //Price.DataField = "BaseRevenue";
            //Price.HeaderText = "Per-Item Cost";
            //Price.HtmlEncode = false;
            //BoundField shipping = new BoundField();
            //shipping.DataField = "SecondaryRevenue";
            //shipping.HeaderText = "Shipping Cost Per Item";
            //shipping.HtmlEncode = false;
            //BoundField quantity = new BoundField();
            //quantity.DataField = "Quantity";
            //quantity.HeaderText = "Quantity";
            //quantity.HtmlEncode = false;
            //GridView1.Columns.Clear();
            //GridView1.Columns.Add(desc);
            //GridView1.Columns.Add(Price);
            //GridView1.Columns.Add(shipping);
            //GridView1.Columns.Add(quantity);
            //GridView1.AutoGenerateColumns = false;
            //GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //GridView1.DataBind();
        }
        else if (pnlViewOrder.Visible)
        { 
            buildOrder();
             
            BoundField desc = new BoundField();
            desc.DataField = "ProductDesc";
            desc.HeaderText = "Product Description";
            desc.HtmlEncode = false;
            BoundField Price = new BoundField();
            Price.DataField = "BaseRevenue";
            Price.HeaderText = "Per-Item Cost";
            Price.HtmlEncode = false;
            BoundField shipping = new BoundField();
            shipping.DataField = "SecondaryRevenue";
            shipping.HeaderText = "Shipping Cost Per Item";
            shipping.HtmlEncode = false;
            BoundField quantity = new BoundField();
            quantity.DataField = "Quantity";
            quantity.HeaderText = "Quantity";
            quantity.HtmlEncode = false;
            gvViewOrder.Columns.Clear();
            gvViewOrder.Columns.Add(desc);
            gvViewOrder.Columns.Add(Price);
            gvViewOrder.Columns.Add(shipping);
            gvViewOrder.Columns.Add(quantity);
            gvViewOrder.AutoGenerateColumns = false;
            gvViewOrder.DataSource = ((DataAccess)Session["App"]).GetOrder();
            gvViewOrder.DataBind();
            lblrMultiPayTotal1st0.Text = GetOrderTotalPerItemShipping().ToString("N2");
            lblrMultiPayTotal0.Text = GetRecurringPayment().ToString("N2");
            lblrOnePayTotal0.Text = (GetOrderTotalPerItemShipping() + (2 * GetRecurringPayment())).ToString("N2");
        }

        if (ddlPaymentType.SelectedItem.Value == "EC" && GetOrderTotalPerItemShipping() > 300.00)//Convert.ToDouble(lblrOnePayTotal.Text) > 300.00)
        {
            lblrOver300.Visible = true;
            Page.SetFocus(lblrOver300);
        }
        else
        {
            lblrOver300.Visible = false;
        }
        if (ddlPaymentType.SelectedItem.Value == "EC")
        {
            lblECError.Visible = true;
            pnlECheck.Visible = true;
            bShowBInfo = true;
            ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
            ((DataAccess)Session["App"]).PutCallData("RecurringTotal","0");
        }
        else
        {
            lblECError.Visible = false;
            pnlECheck.Visible = false;
            if (cbOnePay.Checked)
            {
                ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrOnePayTotal.Text);
                ((DataAccess)Session["App"]).PutCallData("RecurringTotal", "0");
            }
            else
            {
                ((DataAccess)Session["App"]).PutCallData("UpFrontTotal", lblrMultiPayTotal1st.Text);
                ((DataAccess)Session["App"]).PutCallData("RecurringTotal", lblrMultiPayTotal2.Text);
            }
        }

        if (cbShipping.Checked)
        {
            if (tbShipAddr.Text.Replace(".", "").Replace(" ", "").Length >= 5)
            {
                if (tbShipAddr.Text.Replace(".", "").Replace(" ", "").Substring(0, 5).ToUpper() == "POBOX")
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text.Replace(",", "").Replace(".", ""));
                    pnlPOBOX.Visible = true;
                    bShowBInfo = true;
                }
                else
                {
                    pnlPOBOX.Visible = false;
                }
            }
        }
        else
        {
            if (tbAddr.Text.Replace(".", "").Replace(" ", "").Length >= 5)
            {
                if (tbAddr.Text.Replace(".", "").Replace(" ", "").Substring(0, 5).ToUpper() == "POBOX")
                {
                    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text.Replace(",", "").Replace(".", ""));
                    ((DataAccess)Session["App"]).PutCallData("Address1", tbAddr.Text.Replace(",", "").Replace(".", ""));
                    pnlPOBOX.Visible = true;
                    bShowBInfo = true;
                }
                else
                {
                    pnlPOBOX.Visible = false;
                }
            }

        }
        if (bShowBInfo)
        {
            pnlWizard.Visible = false;
            pnlViewOrder.Visible = false;
            pnlFAQ.Visible = false;
            pnlMainReb.Visible = false;
            pnlInfo.Visible = true;
            btnViewOrder.Visible = false;
            btnSave.Visible = false;
            btnFAQ.Visible = false;
        }

        ((DataAccess)Session["App"]).CommitCallData();
        //((DataAccess)Session["App"]).PutCallData("ShippingSame", cbShipping.Checked.ToString());


        //if (cbShipping.Checked)
        //{
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbShipAddr.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbShipaddr2.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlShipCity.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedItem.Text);
        //}
        //else
        //{
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCity", ddlCity.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedItem.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text);
        //    ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedItem.Text);
        //}
    }

    ///***************************
    protected void ddlPaymentType_SelectedIndexChanged(object sender, EventArgs e)
    {
        pnlECheck.Visible = false;
        Session["CInfo"] = false;
        updateRecapTable();
            //buildOrder();
            //BoundField desc = new BoundField();
            //desc.DataField = "ProductDesc";
            //desc.HeaderText = "Product Description";
            //desc.HtmlEncode = false;
            //BoundField Price = new BoundField();
            //Price.DataField = "BaseRevenue";
            //Price.HeaderText = "Per-Item Cost";
            //Price.HtmlEncode = false;
            //BoundField shipping = new BoundField();
            //shipping.DataField = "SecondaryRevenue";
            //shipping.HeaderText = "Shipping Cost Per Item";
            //shipping.HtmlEncode = false;
            //BoundField quantity = new BoundField();
            //quantity.DataField = "Quantity";
            //quantity.HeaderText = "Quantity";
            //quantity.HtmlEncode = false;
            //GridView1.Columns.Clear();
            //GridView1.Columns.Add(desc);
            //GridView1.Columns.Add(Price);
            //GridView1.Columns.Add(shipping);
            //GridView1.Columns.Add(quantity);
            //GridView1.AutoGenerateColumns = false;
            //GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //GridView1.DataBind();
        lblrOnePayTotal.Text = GetOrderTotalPerItemShipping().ToString("N2");
        lblrMultiPayTotal1st.Text = GetOrderTotalPerItemShipping().ToString("N2");
        lblrMultiPayTotal2.Text = GetRecurringPayment().ToString("N2");
        if (ddlPaymentType.SelectedValue == "CC")
        {
            trCCNumber.Visible = true;
            trCCType.Visible = true;
            trCCExpDate.Visible = true;
            //trCCV.Visible = true;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            trECAccHolder.Visible = false;
            tbAccHolder.Text = "";
            tbAccNum.Text = "";
            tbBankName.Text = "";
            tbRoutNum.Text = "";
            tbCheckNum.Text = "";
            if (cbOnePay.Checked)
            {
                pnlrOnePayTotal.Visible = true;
                pnlrMultiPayTotal.Visible = false;
            }
            else
            {
                pnlrOnePayTotal.Visible = false;
                pnlrMultiPayTotal.Visible = true;
            }

        }
        else if (ddlPaymentType.SelectedValue == "EC")
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            //trCCV.Visible = false;
            trECAccNum.Visible = true;
            trECBankName.Visible = true;
            trECCheckNum.Visible = true;
            trECRoutNum.Visible = true;
            trECAccType.Visible = true;
            trECAccHolder.Visible = true;
            pnlECheck.Visible = true;
            tbCCNumber.Text = "";
            tbExpDate.Text = "";

            pnlrOnePayTotal.Visible = true;
            pnlrMultiPayTotal.Visible = false;
        }
        else //They changed it from EC or CC to blank
        {
            trCCNumber.Visible = false;
            trCCType.Visible = false;
            trCCExpDate.Visible = false;
            //trCCV.Visible = false;
            trECAccNum.Visible = false;
            trECBankName.Visible = false;
            trECCheckNum.Visible = false;
            trECRoutNum.Visible = false;
            trECAccType.Visible = false;
            tbCCNumber.Text = "";
            tbExpDate.Text = "";
            tbAccHolder.Text = "";
            tbAccNum.Text = "";
            tbBankName.Text = "";
            tbRoutNum.Text = "";
            tbCheckNum.Text = "";

            if (cbOnePay.Checked)
            {
                pnlrOnePayTotal.Visible = true;
                pnlrMultiPayTotal.Visible = false;
            }
            else
            {
                pnlrOnePayTotal.Visible = false;
                pnlrMultiPayTotal.Visible = true;
            }
        }
        

    }

    protected void cbMini_CheckedChanged(object sender, EventArgs e)
    {
        if (cbMini.Checked)
        {
            cbRefurb.Checked = false;
        }
            OnePayPanels();
    }
    protected void cbRefurb_CheckedChanged(object sender, EventArgs e)
    {
        if (cbRefurb.Checked)
        {
            cbMini.Checked = false;
        }
            OnePayPanels();
    }
    protected void OnePayPanels()
    {
        Page.SetFocus(ddlMainProd);
        if (cbMini.Checked)
        {
            //No way currently to add these as individual products //aaaa
            ddlExtenderRingQty.SelectedIndex = 0;
            ddlMainPizzaKitQty.SelectedIndex = 0;

            ddlMainBakingKitQty.SelectedIndex = 0;
            ddlMainTwistMixQty.SelectedIndex = 0;
            ddlCarryingCaseQty.SelectedIndex = 0;

            pnlBlack.Visible = false;
            cbBlackOvens.Checked = false;
            pnlOnePayVerbiage1.Visible = false;
            pnlOnePayVerbiage2.Visible = false;
            pnlOnePayVerbiage3.Visible = true;

            pnlBakingKit.Visible = false;
            pnlCarryingCase.Visible = false;
            pnlTwistMix.Visible = false;
            pnlERK.Visible = false;
            pnlSPK.Visible = false;
        }
        else if (cbRefurb.Checked)
        {

            pnlBlack.Visible = false;
            cbBlackOvens.Checked = false;
            pnlOnePayVerbiage1.Visible = false;
            pnlOnePayVerbiage2.Visible = true;
            pnlOnePayVerbiage3.Visible = false;
            pnlAddtlOvensVerbiage2.Visible = true;
            pnlAddtlOvensVerbiage1.Visible = false;


            pnlBakingKit.Visible = true;
            pnlCarryingCase.Visible = true;
            pnlTwistMix.Visible = true;
            pnlERK.Visible = true;
            pnlSPK.Visible = true;
        }
        else
        {

            pnlBlack.Visible = true;
            pnlOnePayVerbiage1.Visible = true;
            pnlOnePayVerbiage2.Visible = false;
            pnlOnePayVerbiage3.Visible = false;
            pnlAddtlOvensVerbiage2.Visible = false;
            pnlAddtlOvensVerbiage1.Visible = true;

            pnlBakingKit.Visible = true;
            pnlCarryingCase.Visible = true;
            pnlTwistMix.Visible = true;
            pnlERK.Visible = true;
            pnlSPK.Visible = true;
        }

    }
    protected void cbShipping_CheckedChanged(object sender, EventArgs e)
    {
        if (cbShipping.Checked)
        {

            trShipAddr.Visible = true;
            trShipAddr2.Visible = true;
            trShipPOBoxOption.Visible = true;
            trShipCity.Visible = true;
            trShipState.Visible = true;
            trShipCountry.Visible = true;
            trShipZip.Visible = true;
            trShipLbl.Visible = true;
            trShipSearchZip.Visible = true;

        }
        else
        {
            trShipAddr.Visible = false;
            trShipAddr2.Visible = false;
            trShipPOBoxOption.Visible = false;
            trShipCity.Visible = false;
            trShipState.Visible = false;
            trShipCountry.Visible = false;
            trShipZip.Visible = false;
            trShipLbl.Visible = false;
            trShipSearchZip.Visible = false;
        }
    }

    protected void btnSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbZip.Text.ToUpper(), ddlCity, ddlState, ddlCountry);
        if (cbShipping.Checked)
        {
            if (ddlShipCountry.SelectedItem.Text == "CANADA")
            {
                ddlPaymentType.Items[2].Enabled = false;
            }
        }
        else if (ddlCountry.SelectedItem.Text == "CANADA")
        {
            ddlPaymentType.Items[2].Enabled = false;
        }
        else
        {
            ddlPaymentType.Items[2].Enabled = true;
        }
        btnSubmit_Click(null, null);
    }

    protected void btnShipSearchZip_Click(object sender, EventArgs e)
    {
        ValidateZip(tbShipZip.Text.ToUpper(), ddlShipCity, ddlShipState, ddlShipCountry);
        if (cbShipping.Checked)
        {
            if (ddlShipCountry.SelectedItem.Text == "CANADA")
            {
                ddlPaymentType.Items[2].Enabled = false;
            }
            else
            {
                ddlPaymentType.Items[2].Enabled = true;
            }
        }
        btnSubmit_Click(null, null);
    }

    protected void ValidateZip(string strZip, DropDownList ddl_City, DropDownList ddl_State, DropDownList ddl_Country)
    {

        ddl_City.Items.Clear();
        ddl_State.Items.Clear();
        ddl_City.Enabled = true;
        ddl_State.Enabled = true;
        if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} +\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {
                com.codebump.GeoPlaces g = new com.codebump.GeoPlaces();

                com.codebump.AuthenticationHeader authHeader = new com.codebump.AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                com.codebump.GeoPlaceDistance[] places = g.GetPlacesInside(strZip, "");

                for (int i = 0; i < places.Length; i++)
                {
                    com.codebump.GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddl_City.Items.Add(li);
                }

                ddl_State.Items.Add(ddl_City.SelectedItem.Value.Split(",".ToCharArray())[0]);
                
                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(strZip.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddl_Country.SelectedValue = "CANADA";
                }
                else
                {
                    ddl_Country.SelectedValue = "USA";
                }

                if (ddl_City.Items.Count <= 0)
                {
                    ddl_City.Items.Add("No Cities Found");
                    ddl_State.Items.Add("No States Found");
                    ddl_City.Enabled = false;
                    ddl_State.Enabled = false;
                }
                else
                {
                    ddl_City.Items.Insert(0, "Select a City");
                    ddl_City.SelectedIndex = 0;
                    ddl_State.Enabled = false;
                }
            }
            catch
            {
                ddl_City.Items.Add("No Cities Found");
                ddl_State.Items.Add("No States Found");
                ddl_City.Enabled = false;
                ddl_State.Enabled = false;
            }
        }
        else
        {
            ddl_City.Items.Add("Invalid Zip");
            ddl_City.Enabled = false;
            ddl_State.Items.Add("Invalid Zip");
            ddl_State.Enabled = false;
        }
    }

    public DataAccess.CardType GetCardType(string cardType)
    {
        switch (cardType)
        {
            case "A":
                return DataAccess.CardType.AmericanExpress;
            case "V":
                return DataAccess.CardType.Visa;
            case "D":
                return DataAccess.CardType.Discover;
            case "M":
                return DataAccess.CardType.MasterCard;
            default:
                return DataAccess.CardType.Visa;
        }
    }
    protected void cbPOBox_CheckedChanged(object sender, EventArgs e)
    {

        tbAddr.Text = "";
        tbAddr2.Text = "";
        if (cbPOBox.Checked)
        {
            Page.SetFocus(tbAddr);
            tbAddr.Text = "PO BOX ";
            trAddr2.Visible = false;
        }
        else
        {
            trAddr2.Visible = true;
        }
    }
    protected void cbShipPOBox_CheckedChanged(object sender, EventArgs e)
    {
        tbShipAddr.Text = "";
        tbShipaddr2.Text = "";
        if (cbShipPOBox.Checked)
        {
            tbShipAddr.Text = "PO BOX ";
            trShipAddr2.Visible = false;
            Page.SetFocus(tbShipAddr);
        }
        else
        {
            trShipAddr2.Visible = true;
        }
    }

    public double GetOrderTotalPerItemShipping()
    {
        double BaseTotal = 0.00;
        double ShippingTotal = 0.00;
        for (int i = 0; i < (((DataAccess)Session["App"]).GetOrder()).Rows.Count; i++)
        {
            BaseTotal += Convert.ToDouble((Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["BaseRevenue"])) * Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["Quantity"]));
            ShippingTotal = ShippingTotal + Convert.ToDouble((Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["SecondaryRevenue"])) * Convert.ToDouble((((DataAccess)Session["App"]).GetOrder()).Rows[i]["Quantity"]));
        }

        if (cbShipping.Checked)
        {
            if (ddlShipState.Items.Count > 0)   //error checking to make sure there is a state
            {
                if (ddlShipState.SelectedItem.Text == "IL")
                {
                    BaseTotal *= 1.07;
                }
            }
        }
        else
        {
            if (ddlState.Items.Count > 0)//error checking to make sure there is a state
            {
                if (ddlState.SelectedItem.Text == "IL")
                {
                    BaseTotal *= 1.07;
                }
            }
        }
        return Math.Round((BaseTotal + ShippingTotal), 2);
    }
    public double GetRecurringPayment()
    {
        double secTotal = 0.00;
        DataTable productscomp = new DataTable();
        for (int i = 0; i < (((DataAccess)Session["App"]).GetOrder()).Rows.Count; i++)
        {

            //productscomp = ((DataAccess)Session["App"]).GetProducts("ProductID = " + ((DataAccess)Session["App"]).GetOrder().Rows[i]["ProductID"].ToString());
            productscomp = ((DataAccess)Session["App"]).GetProducts("ProductID", ((DataAccess)Session["App"]).GetOrder().Rows[i]["ProductID"].ToString());
            if (productscomp.Rows[0]["Group2"].ToString() == "3-pay" || productscomp.Rows[0]["Group2"].ToString() == "4-pay")
            {
                secTotal += Convert.ToDouble(Convert.ToDouble(((DataAccess)Session["App"]).GetOrder().Rows[i]["BaseRevenue"]) * Convert.ToDouble(((DataAccess)Session["App"]).GetOrder().Rows[i]["Quantity"]));
            }

        }

        if (cbShipping.Checked)
        {
            if (ddlShipState.Items.Count > 0) //error checking to make sure there is a state
            {
                if (ddlShipState.SelectedItem.Text == "IL")
                {
                    secTotal *= 1.07;
                }
            }
        }
        else
        {
            if (ddlState.Items.Count > 0) //error checking to make sure there is a state
            {
                if (ddlState.SelectedItem.Text == "IL")
                {
                    secTotal *= 1.07;
                }
            }
        }
        return Math.Round(secTotal, 2);
    }
    protected void ddlAddtlOvenQty_SelectedIndexChanged(object sender, EventArgs e)
    {
        Page.SetFocus(ddlAddtlOvenQty);
        //if (ddlAddtlOvenQty.SelectedIndex > 0 && (ddlMainBakingKitQty.SelectedIndex > 0 || (ddlMainTwistMixQty.SelectedIndex > 0 && rblTwistMix.SelectedIndex >= 0) || ddlMainPizzaKitQty.SelectedIndex > 0))
        //{
        //    pnlAddOvenFreebees.Visible = true;
        //}
        //else
        //{
        //    pnlAddOvenFreebees.Visible = false;
        //}
        ////dynamically determines quantity of upsells/freebees that can be purchased
        //if (ddlMainBakingKitQty.SelectedIndex > 0)
        //{
        //    trBakingKit.Visible = true;
        //}
        //else
        //{
        //    trBakingKit.Visible = false;
        //}
        //if (ddlMainTwistMixQty.SelectedIndex > 0 && rblTwistMix.SelectedIndex >= 0)
        //{
        //    trTwistMix.Visible = true;
        //}
        //else
        //{
        //    trTwistMix.Visible = false;
        //}
        //if (ddlMainPizzaKitQty.SelectedIndex > 0)
        //{
        //    trPizzaKit.Visible = true;
        //}
        //else
        //{
        //    trPizzaKit.Visible = false;
        //}


        ListItem templi = new ListItem();

        templi.Text = "Select a quantity";
        templi.Value = "0";
        ddlExtenderRingQty.Items.Clear();
        ddlCarryingCaseQty.Items.Clear();
        ddlMainBakingKitQty.Items.Clear();
        ddlMainTwistMixQty.Items.Clear();
        ddlMainPizzaKitQty.Items.Clear();
        templi.Selected = true;
        ddlExtenderRingQty.Items.Insert(0, templi);
        ddlCarryingCaseQty.Items.Insert(0, templi);
        ddlMainBakingKitQty.Items.Insert(0, templi);
        ddlMainTwistMixQty.Items.Insert(0, templi);
        ddlMainPizzaKitQty.Items.Insert(0, templi);

        //dynamically determines quantity of extender rings and carrying cases that can be purchased

        for (Int32 i = 1; i <= (Convert.ToInt32(ddlMainProd.SelectedValue) + Convert.ToInt32(ddlAddtlOvenQty.SelectedValue)); i++)
        {
            ListItem item = new ListItem();
            item.Text = i.ToString();
            item.Value = i.ToString();
            item.Selected = false;
            ddlExtenderRingQty.Items.Add(item);
            ddlCarryingCaseQty.Items.Add(item);
            ddlMainBakingKitQty.Items.Add(item);
            ddlMainTwistMixQty.Items.Add(item);
            ddlMainPizzaKitQty.Items.Add(item);
        }

    }

    protected void ddlMainProd_SelectedIndexChanged(object sender, EventArgs e)
    {
        Page.SetFocus(ddlMainProd);
        if (ddlMainProd.SelectedIndex == 1)
        {
            pnlAddtlOvens.Visible = true;
        }
        else
        {
            ddlAddtlOvenQty.SelectedIndex = 0;
            ddlAddtlOvenQty_SelectedIndexChanged(null, null);
            pnlAddtlOvens.Visible = false;
        }

        cbMini_CheckedChanged(null, null);

    }


    protected void buildOrder()
    {
        ((DataAccess)Session["App"]).GetOrder().Rows.Clear();
        if (Convert.ToInt32(ddlMainProd.SelectedValue) > 0) //This if statement is just a failsafe in case they are somehow able to get to the upsell page without having any ovens ordered
        {

            Session["ERK"] = ddlExtenderRingQty.SelectedValue;
            Session["SPK"] = ddlMainPizzaKitQty.SelectedValue;
            //get quantities for products
            //the principle behind this whole mess is that all upsells/downsells will be <= mainoven qty + addtloven qty
            //NOTE: decremented by qty needs to be last when decrementing fields so it's not 0'ed before decrement
            addMainProdCombos();
            addAdditionalCombos();
            addUpsellFreebie();

            //add stuff that's free with every order
            ((DataAccess)Session["App"]).PutOrderItem(225, 1); //warranty, dvd, recipe
            ((DataAccess)Session["App"]).PutOrderItem(226, 1); //Free memberhsip to nuwave cooking club
            ((DataAccess)Session["App"]).PutOrderItem(223, 1); //$100 downsell

            //add next day processing
            if (rbl24Hour.SelectedIndex == 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(222, 1); //24 hour processing
                ((DataAccess)Session["App"]).PutCallData("NextDayShip", "1");
            }
            else
            {
                ((DataAccess)Session["App"]).PutCallData("NextDayShip", "0");
            }

            //add discounts
            if (ddlMainPizzaKitQty.SelectedIndex > 0 && cbPKDown.Checked)// Session["Pizza"].ToString() == "downsell")
            {
                ((DataAccess)Session["App"]).PutOrderItem(234, 1); //pizza discount for first kit
            }

            if (cbHalfShip.Checked && !cbRefurb.Checked && !cbMini.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
            }

            addSurchargeShipping();
        }
    }
    protected void addMainProdCombos()
    {
        //int mainoven = Convert.ToInt32(ddlMainProd.SelectedValue);
        //int supremepizza = Convert.ToInt32(Session["SPK"]);//Convert.ToInt32(ddlMainPizzaKitQty.SelectedValue);
        //int extenderring = Convert.ToInt32(Session["ERK"]);
        //int addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue); //this quantity is needed to be able to add appropriate number of discounts for black oven
        //int counter = 0;
        //do logic for single-pay items
        if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
        {
            //aaaa
            if (cbMini.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(210, 1); //single-pay mini             
            }
            else if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
            {
                CCCCombo_Builder(204, 186, 199, 181, "Main");
            }
            else if (cbRefurb.Checked) //do logic for single pay refurb combos (only available in white)
            {
                CCCCombo_Builder(467, 455, 461, 449, "Main");
            }
            else //do logic for non-black single-pay combos
            {
                CCCCombo_Builder(194, 176, 190, 171, "Main");
            }
        }
        else if (cbfourpay.Checked)
        {
            //aaaa
            if (cbMini.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(448, 1); //4-pay mini             
            }
            else if (cbBlackOvens.Checked) //do logic for 4-pay black items
            {
                CCCCombo_Builder(445, 437, 443, 435, "Main");
            }
            else if (cbRefurb.Checked) //do logic for 4-pay refurb combos (only available in white)
            {
                CCCCombo_Builder(469, 457, 463, 451, "Main");
            }
            else //do logic for 4-pay non-black items
            {
                CCCCombo_Builder(441, 433, 439, 431, "Main");
            }
        }
        else
        {
            //do logic for 3-pay items
            //aaaa
            if (cbMini.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(211, 1); //3-pay mini             
            }
            else if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
            {
                CCCCombo_Builder(205, 187, 201, 182, "Main");
            }
            else if (cbRefurb.Checked) //do logic for 3-pay refurb combos (only available in white)
            {
                CCCCombo_Builder(468, 456, 462, 450, "Main");
            }
            else //do logic for 3-pay non-black combos
            {
                CCCCombo_Builder(196, 178, 191, 173, "Main");
            }
        }
        #region oldway
        //if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
        //{
        //    //if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
        //    //{

        //    //    //add black main, supreme pizza, ext ring combo and decrement all by 1 until one of them = 0
        //    //    while (supremepizza > 0 && extenderring > 0 && mainoven > 0)
        //    //    {
        //    //        counter += 1;
        //    //        supremepizza -= 1;
        //    //        extenderring -= 1;
        //    //        mainoven -= 1;
        //    //    }
        //    //    if (counter > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(358, counter);
        //    //    }

        //    //    counter = 0; //reset counter

        //    //    while (mainoven > 0 && extenderring > 0)
        //    //    {
        //    //        counter += 1;
        //    //        supremepizza -= 1;
        //    //        mainoven -= 1;
        //    //    }
        //    //    if (counter > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(358, counter);
        //    //    }

        //    //    counter = 0; //reset counter

        //    //    while (supremepizza > 0 && mainoven > 0)
        //    //    {
        //    //        counter += 1;
        //    //        supremepizza -= 1;
        //    //        mainoven -= 1;
        //    //    }
        //    //    if (counter > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(358, counter);
        //    //    }

        //    //    if (mainoven > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(181, mainoven); //black main leftover (will be 0 if any combos are ordered)
        //    //    }
        //    //}
        //    //else//do logic for single-pay non-black oven combos
        //    //{

        //    //    //add non-black main, supreme pizza, ext ring combo and decrement all by 1 until one of them = 0
        //    //    while (supremepizza > 0 && extenderring > 0 && mainoven > 0)
        //    //    {
        //    //        counter += 1;
        //    //        supremepizza -= 1;
        //    //        extenderring -= 1;
        //    //        mainoven -= 1;
        //    //    }
        //    //    if (counter > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(358, counter);
        //    //    }

        //    //    counter = 0; //reset counter

        //    //    while (mainoven > 0 && extenderring > 0)
        //    //    {
        //    //        counter += 1;
        //    //        supremepizza -= 1;
        //    //        mainoven -= 1;
        //    //    }
        //    //    if (counter > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(358, counter);
        //    //    }

        //    //    counter = 0; //reset counter

        //    //    while (supremepizza > 0 && mainoven > 0)
        //    //    {
        //    //        counter += 1;
        //    //        supremepizza -= 1;
        //    //        mainoven -= 1;
        //    //    }
        //    //    if (counter > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(358, counter);
        //    //    }

        //    //    if (mainoven > 0)
        //    //    {
        //    //        ((DataAccess)Session["App"]).PutOrderItem(181, mainoven); //black main leftover (will be 0 if any combos are ordered)
        //    //    }
        //    //} //end black/non-black oven check for single-pay
        //}
        //else if (cbfourpay.Checked)
        //{
        //}
        //else
        //{
        //    //do logic for 3-pay items
        //    if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
        //    {
        //        //add black 1st, supreme pizza, ext ring combo
        //        if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
        //        {
        //            if (extenderring > mainoven)
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(205, mainoven);
        //                supremepizza -= mainoven;
        //                extenderring -= mainoven;
        //                mainoven -= mainoven; //0's out main oven
        //            }
        //            else
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(205, extenderring);

        //                supremepizza -= extenderring;
        //                mainoven -= extenderring;
        //                extenderring -= extenderring; //0's out the extender rings
        //            }
        //        }
        //        if (mainoven > 0 && extenderring > 0)
        //        {
        //            if (extenderring > mainoven)
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(187, mainoven); // 1st plus ext ring
        //                extenderring -= mainoven;
        //                mainoven -= mainoven; //0's out main oven
        //            }
        //            else
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(187, extenderring); // 1st plus ext ring
        //                mainoven -= extenderring;
        //                extenderring -= extenderring;//0's out extring if <= main
        //            }
        //        }
        //        if (mainoven > 0 && supremepizza > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(201, mainoven); //black 1st plus supreme
        //            supremepizza -= mainoven;
        //            mainoven -= mainoven;
        //        }
        //        if (mainoven > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(182, mainoven); //black main leftover (will be 0 if any combos are ordered)
        //        }
        //    }
        //    else //do logic for 3-pay non-black oven combos
        //    {
        //        //add 1st, supreme pizza, ext ring combo
        //        if (supremepizza > 0 && extenderring > 0 && mainoven > 0)
        //        {
        //            if (extenderring > mainoven)
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(196, mainoven);
        //                supremepizza -= mainoven;
        //                extenderring -= mainoven;
        //                mainoven -= mainoven; //0's out main oven
        //            }
        //            else
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(196, extenderring);

        //                supremepizza -= extenderring;
        //                mainoven -= extenderring;
        //                extenderring -= extenderring; //0's out the extender rings
        //            }
        //        }
        //        if (mainoven > 0 && extenderring > 0)
        //        {
        //            if (extenderring > mainoven)
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(178, mainoven); // 1st plus ext ring
        //                extenderring -= mainoven;
        //                mainoven -= mainoven; //0's out main oven
        //            }
        //            else
        //            {
        //                ((DataAccess)Session["App"]).PutOrderItem(178, extenderring); // 1st plus ext ring
        //                mainoven -= extenderring;
        //                extenderring -= extenderring;//0's out extring if <= main
        //            }
        //        }
        //        if (mainoven > 0 && supremepizza > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(191, mainoven); //1st plus supreme pizza
        //            supremepizza -= mainoven;
        //            mainoven -= mainoven;
        //        }
        //        if (mainoven > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(173, mainoven); //leftover main oven
        //        }
        //    } //end segregation check
        //}//ends the if(cbonepay.checked) statement
        #endregion
    }
    protected void addAdditionalCombos()
    {
        if (Convert.ToInt32(ddlAddtlOvenQty.SelectedValue) > 0) //If we have addtl ovens, add combos for them.
        {
            if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
            {
                if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
                {
                    CCCCombo_Builder(206, 188, 202, 183, "Addtl");
                }
                else if (cbRefurb.Checked) //do logic for single pay refurb combos (only available in white)
                {
                    CCCCombo_Builder(470, 458, 464, 452, "Addtl");
                }
                else //do logic for non-black non-refurb single-pay combos
                {
                    CCCCombo_Builder(197, 179, 192, 174, "Addtl");
                }
            }
            else if (cbfourpay.Checked)
            {
                if (cbBlackOvens.Checked) //do logic for 4-pay black items
                {
                    CCCCombo_Builder(446, 438, 444, 436, "Addtl");
                }
                else if (cbRefurb.Checked) //do logic for 4-pay refurb combos (only available in white)
                {
                    CCCCombo_Builder(472, 460, 466, 454, "Addtl");
                }
                else //do logic for 4-pay non-black non-refurb items
                {
                    CCCCombo_Builder(442, 434, 440, 432, "Addtl");
                }
            }
            else
            {
                //do logic for 3-pay items
                if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
                {
                    CCCCombo_Builder(207, 189, 203, 185, "Addtl");
                }
                else if (cbRefurb.Checked) //do logic for 3-pay refurb combos (only available in white)
                {
                    CCCCombo_Builder(471, 459, 465, 453, "Addtl");
                }
                else //do logic for 3-pay non-black non-refurb combos
                {
                    CCCCombo_Builder(198, 180, 193, 175, "Addtl");
                }
            }
            #region oldway
            ////do logic for single-pay items
            //if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
            //{
            //    if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
            //    {
            //        //add black add'l, supreme pizza, ext ring combo
            //        if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
            //        {
            //            //decrement by extenderring and put in that qty
            //            if (addtlsupremepizza > addtlextenderring)
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(206, addtlextenderring);
            //                addtlovens -= addtlextenderring;
            //                addtlsupremepizza -= addtlextenderring;
            //                addtlextenderring -= addtlextenderring;
            //            }
            //            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
            //            else
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(206, addtlsupremepizza);
            //                addtlovens -= addtlsupremepizza;
            //                addtlextenderring -= addtlsupremepizza;
            //                addtlsupremepizza -= addtlsupremepizza;
            //            }

            //        }
            //        if (addtlovens > 0 && addtlextenderring > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(188, addtlextenderring); //black addtl plus ext ring
            //            addtlovens -= addtlextenderring;
            //            addtlextenderring -= addtlextenderring;
            //        }
            //        if (addtlovens > 0 && addtlsupremepizza > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(202, addtlsupremepizza); //black addtl plus supreme
            //            addtlovens -= addtlsupremepizza;
            //            addtlsupremepizza -= addtlsupremepizza;
            //        }
            //        if (addtlovens > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(183, addtlovens); //black addtl leftover
            //        }
            //    }
            //    else//do logic for single-pay non-black oven combos
            //    {
            //        //add add'l, supreme pizza, ext ring combo
            //        if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
            //        {
            //            //decrement by extenderring and put in that qty
            //            if (addtlsupremepizza > addtlextenderring)
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(197, addtlextenderring);
            //                addtlovens -= addtlextenderring;
            //                addtlsupremepizza -= addtlextenderring;
            //                addtlextenderring -= addtlextenderring;
            //            }
            //            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
            //            else
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(197, addtlsupremepizza);
            //                addtlovens -= addtlsupremepizza;
            //                addtlextenderring -= addtlsupremepizza;
            //                addtlsupremepizza -= addtlsupremepizza;
            //            }
            //        }
            //        if (addtlovens > 0 && addtlextenderring > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(179, addtlextenderring); // addtl plus ext ring
            //            addtlovens -= addtlextenderring;
            //            addtlextenderring -= addtlextenderring;
            //        }
            //        if (addtlovens > 0 && addtlsupremepizza > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(192, addtlsupremepizza); //addtl plus supreme pizza
            //            addtlovens -= addtlsupremepizza;
            //            addtlsupremepizza -= addtlsupremepizza;
            //        }
            //        if (addtlovens > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(174, addtlovens); //leftover addtl oven
            //        }
            //    } //end black/non-black oven check

            //}
            //else if (cbfourpay.Checked)
            //{
            //}
            //else
            //{
            //    //do logic for 3-pay items
            //    if (cbBlackOvens.Checked)//do logic for 3-pay black oven combos
            //    {
            //        //add black add'l, supreme pizza, ext ring combo
            //        if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
            //        {
            //            //decrement by extenderring and put in that qty
            //            if (addtlsupremepizza > addtlextenderring)
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(207, addtlextenderring);
            //                addtlovens -= addtlextenderring;
            //                addtlsupremepizza -= addtlextenderring;
            //                addtlextenderring -= addtlextenderring;
            //            }
            //            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
            //            else
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(207, addtlsupremepizza);
            //                addtlovens -= addtlsupremepizza;
            //                addtlextenderring -= addtlsupremepizza;
            //                addtlsupremepizza -= addtlsupremepizza;
            //            }
            //        }
            //        if (addtlovens > 0 && addtlextenderring > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(189, addtlextenderring); //black addtl plus ext ring
            //            addtlovens -= addtlextenderring;
            //            addtlextenderring -= addtlextenderring;
            //        }
            //        if (addtlovens > 0 && addtlsupremepizza > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(203, addtlsupremepizza); //black addtl plus supreme
            //            addtlovens -= addtlsupremepizza;
            //            addtlsupremepizza -= addtlsupremepizza;
            //        }
            //        if (addtlovens > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(185, addtlovens); //black addtl leftover
            //        }
            //    }
            //    else //do logic for 3-pay non-black oven combos
            //    {
            //        //add add'l, supreme pizza, ext ring combo
            //        if (addtlsupremepizza > 0 && addtlextenderring > 0 && addtlovens > 0)
            //        {
            //            //decrement by extenderring and put in that qty
            //            if (addtlsupremepizza > addtlextenderring)
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(198, addtlextenderring);
            //                addtlovens -= addtlextenderring;
            //                addtlsupremepizza -= addtlextenderring;
            //                addtlextenderring -= addtlextenderring;
            //            }
            //            //decrement by supremepizza and put in that qty (works if extender ring is greater than or = supreme pizza)
            //            else
            //            {
            //                ((DataAccess)Session["App"]).PutOrderItem(198, addtlsupremepizza);
            //                addtlovens -= addtlsupremepizza;
            //                addtlextenderring -= addtlsupremepizza;
            //                addtlsupremepizza -= addtlsupremepizza;
            //            }
            //        }
            //        if (addtlovens > 0 && addtlextenderring > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(180, addtlextenderring); // addtl plus ext ring
            //            addtlovens -= addtlextenderring;
            //            addtlextenderring -= addtlextenderring;
            //        }
            //        if (addtlovens > 0 && addtlsupremepizza > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(193, addtlsupremepizza); //addtl plus supreme pizza
            //            addtlovens -= addtlsupremepizza;
            //            addtlsupremepizza -= addtlsupremepizza;
            //        }
            //        if (addtlovens > 0)
            //        {
            //            ((DataAccess)Session["App"]).PutOrderItem(175, addtlovens); //leftover addtl oven
            //        }

            //    } //end segregation check
            //}//ends the if(cbonepay.checked) statement
            #endregion
        } //ends check for additional ovens
    }
    protected void CCCCombo_Builder(int tripleComboID, int ERKComboID, int SPKComboID, int mainProdID, string oventype)
    {
        int mainoven = Convert.ToInt32(ddlMainProd.SelectedValue);
        int supremepizza = Convert.ToInt32(Session["SPK"]);//Convert.ToInt32(ddlMainPizzaKitQty.SelectedValue);
        int extenderring = Convert.ToInt32(Session["ERK"]);
        int addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue); //this quantity is needed to be able to add appropriate number of discounts for black oven
        int counter = 0;
        int ovens = 0;
        if (oventype == "Main")
        {
            ovens = mainoven;
        }
        else
        {
            ovens = addtlovens;
        }

        //add black main, supreme pizza, ext ring combo and decrement all by 1 until one of them = 0
        while (supremepizza > 0 && extenderring > 0 && ovens > 0)
        {
            counter += 1;
            supremepizza -= 1;
            extenderring -= 1;
            ovens -= 1;
        }
        if (counter > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(tripleComboID, counter);
        }

        counter = 0; //reset counter

        while (ovens > 0 && extenderring > 0)
        {
            counter += 1;
            supremepizza -= 1;
            ovens -= 1;
        }
        if (counter > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(ERKComboID, counter);
        }

        counter = 0; //reset counter

        while (supremepizza > 0 && ovens > 0)
        {
            counter += 1;
            supremepizza -= 1;
            ovens -= 1;
        }
        if (counter > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(SPKComboID, counter);
        }

        if (ovens > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(mainProdID, ovens); //black leftover (will be 0 if any combos are ordered)        
        }

        Session["ERK"] = extenderring;
        Session["SPK"] = supremepizza;
    }
    protected void addUpsellFreebie()
    {
        int mainoven = Convert.ToInt32(ddlMainProd.SelectedValue);
        int addtlovens = Convert.ToInt32(ddlAddtlOvenQty.SelectedValue);

        //add non-combo upsells/freebies
        if ((ddlMainBakingKitQty.SelectedIndex) > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(229, (ddlMainBakingKitQty.SelectedIndex)); //baking kit
        }
        if (rblTwistMix.SelectedIndex == 0 && (ddlMainTwistMixQty.SelectedIndex) > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(227, (ddlMainTwistMixQty.SelectedIndex)); //party mixer
            ((DataAccess)Session["App"]).PutOrderItem(228, (ddlMainTwistMixQty.SelectedIndex)); //twister free (comes with the party mixer)
        }
        if (rblTwistMix.SelectedIndex == 1 && (ddlMainTwistMixQty.SelectedIndex) > 0)
        {
            ((DataAccess)Session["App"]).PutOrderItem(224, (ddlMainTwistMixQty.SelectedIndex)); //twister
        }
        //do logic for single-pay items
        if (cbOnePay.Checked || ddlPaymentType.SelectedValue == "EC")
        {
            if (ddlCarryingCaseQty.SelectedIndex > 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(208, ddlCarryingCaseQty.SelectedIndex); //add 1-pay carrying case
            }
            if (cbBlackOvens.Checked) //do logic for black oven single-pay combos
            {
                if (cbBlackDwn.Checked)// Convert.ToBoolean(Session["BlackReb"]))//check to see if we need to give the discounted price for black ovens
                {
                    ((DataAccess)Session["App"]).PutOrderItem(237, mainoven + addtlovens); //add black oven discount 1-pay
                }
            }
            if (cbERKDown2.Checked && ddlExtenderRingQty.SelectedIndex > 0)// Session["ERKDownsell"].ToString() == "Downsell2")
            {
                ((DataAccess)Session["App"]).PutOrderItem(230, ddlExtenderRingQty.SelectedIndex); //extender ring free
            }
            else if (cbERKDown1.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell1")
            {
                ((DataAccess)Session["App"]).PutOrderItem(232, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 1-pay
            }
        }
        else if (cbfourpay.Checked)
        {
            if (ddlCarryingCaseQty.SelectedIndex > 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(447, ddlCarryingCaseQty.SelectedIndex); //add 4-pay carrying case
            }
            if (cbBlackOvens.Checked) //do logic for black oven 4-pay combos
            {
                if (cbBlackDwn.Checked)// Convert.ToBoolean(Session["BlackReb"]))//check to see if we need to give the discounted price for black ovens
                {
                    ((DataAccess)Session["App"]).PutOrderItem(474, mainoven + addtlovens); //add black oven discount 4-pay
                }
            }
            if (cbERKDown2.Checked && ddlExtenderRingQty.SelectedIndex > 0)// Session["ERKDownsell"].ToString() == "Downsell2")
            {
                ((DataAccess)Session["App"]).PutOrderItem(476, ddlExtenderRingQty.SelectedIndex); //extender ring free
            }
            else if (cbERKDown1.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell1")
            {
                ((DataAccess)Session["App"]).PutOrderItem(475, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 4-pay
            }
        }
        else
        {
            if (ddlCarryingCaseQty.SelectedIndex != 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(209, ddlCarryingCaseQty.SelectedIndex); //add 3-pay carrying case
            }
            if (cbBlackOvens.Checked)
            {
                if (cbBlackDwn.Checked)// Convert.ToBoolean(Session["BlackReb"]))//check to see if we need to give the discounted price for black ovens
                {
                    ((DataAccess)Session["App"]).PutOrderItem(238, mainoven + addtlovens); //add black oven discount 3-pay
                }
            }
            if (cbERKDown2.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell2")
            {
                ((DataAccess)Session["App"]).PutOrderItem(231, ddlExtenderRingQty.SelectedIndex); //extender ring free
            }
            else if (cbERKDown1.Checked && ddlExtenderRingQty.SelectedIndex > 0)//Session["ERKDownsell"].ToString() == "Downsell1")
            {
                ((DataAccess)Session["App"]).PutOrderItem(233, ddlExtenderRingQty.SelectedIndex); //extender ring with discount 3-pay
            }
        }
    }
    protected void addSurchargeShipping()
    {
        if (cbShipping.Checked) //if shipping info is visible
        {
            if (ddlShipState.Items.Count <= 0)//error checking to make sure that there is a state selected.
            {
                lblError.Text = "Please enter a valid shipping zip code";
                lblError.Visible = true;
                return;
            }
            Sur_ChargeIt(ddlShipState, ddlShipCountry);
        }
        else
        {
            if (ddlState.Items.Count <= 0)  //error checking to make sure that there is a state selected.
            {
                lblError.Text = "Please enter a valid zip code";
                lblError.Visible = true;
                return;
            }
            Sur_ChargeIt(ddlState, ddlCountry);
        }
        #region oldway
        //if(cbShipping.Checked)
        //{
        //if (ddlShipState.Items.Count <= 0)//error checking to make sure that there is a state selected.
        //{
        //    lblError.Text = "Please enter a valid shipping zip code";
        //    lblError.Visible = true;
        //    return;
        //}
        //    if (ddlAddtlOvenQty.SelectedIndex > 0)
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //discount for additional ovens
        //    }
        //    if (ddlShipCountry.SelectedValue == "CANADA") //if shipping country is canada
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(212, Convert.ToInt32(ddlMainProd.SelectedValue)); //canada surcharge for initial oven

        //        if (cbHalfShip.Checked)
        //        {
        //            ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(213, ddlAddtlOvenQty.SelectedIndex); //canada surcharge addtl oven
        //        }
        //        if (cbRushShip.Checked)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(221, 1); //canada rush shipping
        //            ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if canada
        //        }
                
        //    }
        //    else
        //    {
        //if (cbRushShip.Checked)
        //{
        //    ((DataAccess)Session["App"]).PutOrderItem(220, 1); //US rush shipping
        //    ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
        //}
        //    }
        //    if (ddlShipState.SelectedItem.Text == "PR")
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(217, ddlMainProd.SelectedIndex); //puerto rico surcharge
                
        //        if (cbHalfShip.Checked)
        //        {
        //            //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
        //        }
        //        if ((1 + ddlAddtlOvenQty.SelectedIndex - 1) > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(218, ddlAddtlOvenQty.SelectedIndex); //puerto rico surcharge addtl oven
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if PR
        //        }
               
        //    }
        //    if (ddlShipState.SelectedItem.Text == "AK" || ddlShipState.SelectedItem.Text == "HI")
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(214, ddlMainProd.SelectedIndex); //alaska/hawaii surcharge
                
        //        if (cbHalfShip.Checked)
        //        {
        //            //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
        //        }
        //        else
        //        {
        //            //if (cbRewardCert.Checked)
        //            //{
        //            //    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            //}
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(216, ddlAddtlOvenQty.SelectedIndex); //alaska/hawaii surcharge addtl oven
        //        }
                
        //    }
        //    if (ddlShipState.SelectedItem.Text == "CT" || ddlShipState.SelectedItem.Text == "RI")
        //    {
        //        ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if CT or RI
        //    }
        //}
        //else
        //{
        //if (ddlState.Items.Count <= 0)  //error checking to make sure that there is a state selected.
        //{
        //    lblError.Text = "Please enter a valid zip code";
        //    lblError.Visible = true;
        //    return;
        //}
        //    if (ddlAddtlOvenQty.SelectedIndex > 0)
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //discount for additional ovens
        //    }
        //    if (ddlCountry.SelectedValue == "CANADA")
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(212, ddlMainProd.SelectedIndex); //canada surcharge

        //        if (cbHalfShip.Checked)
        //        {
        //            ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
        //        }
        //        if ((1 + ddlAddtlOvenQty.SelectedIndex - 1) > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(213, ddlAddtlOvenQty.SelectedIndex); //canada surcharge addtl oven
        //        }
        //        if (cbRushShip.Checked)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(221, 1); //canada rush shipping
        //            ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if canada
        //        }
                
        //    }
        //    else
        //    {
        //        if (cbRushShip.Checked)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(220, 1); //US rush shipping
        //            ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
        //        }
        //    }
        //    if (ddlState.SelectedItem.Text == "PR")
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(217, ddlMainProd.SelectedIndex); //puerto rico surcharge

        //        if (cbHalfShip.Checked)
        //        {
        //            //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
        //        }
        //        if ((ddlAddtlOvenQty.SelectedIndex) > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(218, ddlAddtlOvenQty.SelectedIndex); //puerto rico surcharge addtl oven
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if PR
        //        }
                
        //    }
        //    if (ddlState.SelectedItem.Text == "AK" || ddlState.SelectedItem.Text == "HI")
        //    {
        //        ((DataAccess)Session["App"]).PutOrderItem(214, ddlMainProd.SelectedIndex); //alaska/hawaii surcharge
                
        //        if (cbHalfShip.Checked)
        //        {
        //            //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
        //            ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
        //        }
        //        if (ddlAddtlOvenQty.SelectedIndex > 0)
        //        {
        //            ((DataAccess)Session["App"]).PutOrderItem(216, ddlAddtlOvenQty.SelectedIndex); //alaska/hawaii surcharge addtl oven
        //        }
                
        //    }
        //    if (ddlState.SelectedItem.Text == "CT" || ddlState.SelectedItem.Text == "RI")
        //    {
        //        ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if CT or RI
        //    }
        //}
        #endregion
    }
    protected void Sur_ChargeIt(DropDownList state, DropDownList country)
    {
        if(country.SelectedValue == "CANADA")
        {
            ((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //remove $100 reward cert if the order is in Canada
        }

        if (cbRushShip.Checked)
        {
            if (country.SelectedValue == "CANADA")
            {
                ((DataAccess)Session["App"]).PutOrderItem(221, 1); //canada rush shipping
            }
            else
            {
                ((DataAccess)Session["App"]).PutOrderItem(220, 1); //US rush shipping
            }

            ((DataAccess)Session["App"]).PutCallData("Rushship", "1");
        }

        //aaaa not sure if addtl ovens are available for mini's
        if (cbMini.Checked)
        {
            if (country.SelectedValue == "CANADA" || state.SelectedItem.Text == "PR" || state.SelectedItem.Text == "AK" || state.SelectedItem.Text == "HI") 
            {
                ((DataAccess)Session["App"]).PutOrderItem(219, ddlMainProd.SelectedIndex); //mini nuwave surcharge
            }
        }
        else if (cbRefurb.Checked)
        {
            if (country.SelectedValue == "CANADA" || state.SelectedItem.Text == "PR" || state.SelectedItem.Text == "AK" || state.SelectedItem.Text == "HI")
            {
                ((DataAccess)Session["App"]).PutOrderItem(473, ddlMainProd.SelectedIndex + ddlAddtlOvenQty.SelectedIndex); //refurbished nuwave surcharge for all ovens ordered
            }
        }
        else
        {
            if (ddlAddtlOvenQty.SelectedIndex > 0)
            {
                ((DataAccess)Session["App"]).PutOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //discount for additional ovens
            }
            if (country.SelectedValue == "CANADA")
            {
                ((DataAccess)Session["App"]).PutOrderItem(212, ddlMainProd.SelectedIndex); //canada surcharge

                if (cbHalfShip.Checked)
                {
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }

                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(213, ddlAddtlOvenQty.SelectedIndex); //canada surcharge addtl oven
                    ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if canada
                }

            }

            if (state.SelectedItem.Text == "PR")
            {
                ((DataAccess)Session["App"]).PutOrderItem(217, ddlMainProd.SelectedIndex); //puerto rico surcharge

                if (cbHalfShip.Checked)
                {
                    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                if ((ddlAddtlOvenQty.SelectedIndex) > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(218, ddlAddtlOvenQty.SelectedIndex); //puerto rico surcharge addtl oven
                    ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if PR
                }

            }
            if (state.SelectedItem.Text == "AK" || state.SelectedItem.Text == "HI")
            {
                ((DataAccess)Session["App"]).PutOrderItem(214, ddlMainProd.SelectedIndex); //alaska/hawaii surcharge

                if (cbHalfShip.Checked)
                {
                    //((DataAccess)Session["App"]).RemoveOrderItem(223, 1); //$100 downsell
                    ((DataAccess)Session["App"]).RemoveOrderItem(236, ddlMainProd.SelectedIndex); //Half shipping discount
                }
                if (ddlAddtlOvenQty.SelectedIndex > 0)
                {
                    ((DataAccess)Session["App"]).PutOrderItem(216, ddlAddtlOvenQty.SelectedIndex); //alaska/hawaii surcharge addtl oven
                }

            }
            if (state.SelectedItem.Text == "CT" || state.SelectedItem.Text == "RI")
            {
                ((DataAccess)Session["App"]).RemoveOrderItem(235, ddlAddtlOvenQty.SelectedIndex); //remove discount for additional ovens if CT or RI
            }

        }
    }
    protected void btnFAQ_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        btnViewOrder.Text = "View Order";
        btnSave.Text = "Save the Sale Rebuttals";
        pnlWizard.Visible = false;
        pnlMainReb.Visible = false;
        pnlViewOrder.Visible = false;

        if (pnlFAQ.Visible)
        {
            pnlFAQ.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlFAQ.Visible = true;
            btnFAQ.Text = "Return to Script";
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        btnViewOrder.Text = "View Order";
        btnSave.Text = "Save the Sale Rebuttals";
        pnlWizard.Visible = false;
        pnlFAQ.Visible = false;
        pnlViewOrder.Visible = false;

        if (pnlMainReb.Visible)
        {
            pnlMainReb.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlMainReb.Visible = true;
            btnSave.Text = "Return to Script";
        }
        if (pnlWizard.Visible)
        {
            updateRecapTable();
            //buildOrder();
            //BoundField desc = new BoundField();
            //desc.DataField = "ProductDesc";
            //desc.HeaderText = "Product Description";
            //desc.HtmlEncode = false;
            //BoundField Price = new BoundField();
            //Price.DataField = "BaseRevenue";
            //Price.HeaderText = "Per-Item Cost";
            //Price.HtmlEncode = false;
            //BoundField shipping = new BoundField();
            //shipping.DataField = "SecondaryRevenue";
            //shipping.HeaderText = "Shipping Cost Per Item";
            //shipping.HtmlEncode = false;
            //BoundField quantity = new BoundField();
            //quantity.DataField = "Quantity";
            //quantity.HeaderText = "Quantity";
            //quantity.HtmlEncode = false;
            //GridView1.Columns.Clear();
            //GridView1.Columns.Add(desc);
            //GridView1.Columns.Add(Price);
            //GridView1.Columns.Add(shipping);
            //GridView1.Columns.Add(quantity);
            //GridView1.AutoGenerateColumns = false;
            //GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
            //GridView1.DataBind();
        }
    }
    protected void btnViewOrder_Click(object sender, EventArgs e)
    {
        btnFAQ.Text = "View FAQ";
        btnViewOrder.Text = "View Order";
        btnSave.Text = "Save the Sale Rebuttals";
        pnlWizard.Visible = false;
        pnlFAQ.Visible = false;
        pnlMainReb.Visible = false;

        if (pnlViewOrder.Visible)
        {
            pnlViewOrder.Visible = false;
            pnlWizard.Visible = true;
        }
        else
        {
            pnlViewOrder.Visible = true;
            btnViewOrder.Text = "Return to Script";
        }
        buildOrder();
        
        BoundField desc = new BoundField();
        desc.DataField = "ProductDesc";
        desc.HeaderText = "Product Description";
        desc.HtmlEncode = false;
        BoundField Price = new BoundField();
        Price.DataField = "BaseRevenue";
        Price.HeaderText = "Per-Item Cost";
        Price.HtmlEncode = false;
        BoundField shipping = new BoundField();
        shipping.DataField = "SecondaryRevenue";
        shipping.HeaderText = "Shipping Cost Per Item";
        shipping.HtmlEncode = false;
        BoundField quantity = new BoundField();
        quantity.DataField = "Quantity";
        quantity.HeaderText = "Quantity";
        quantity.HtmlEncode = false;
        gvViewOrder.Columns.Clear();
        gvViewOrder.Columns.Add(desc);
        gvViewOrder.Columns.Add(Price);
        gvViewOrder.Columns.Add(shipping);
        gvViewOrder.Columns.Add(quantity);
        gvViewOrder.AutoGenerateColumns = false;
        gvViewOrder.DataSource = ((DataAccess)Session["App"]).GetOrder();
        gvViewOrder.DataBind();
        lblrMultiPayTotal1st0.Text = GetOrderTotalPerItemShipping().ToString("N2");
        lblrMultiPayTotal0.Text = GetRecurringPayment().ToString("N2");
        if (cbfourpay.Checked)  //calculate single-pay subtotal for order with 4-pay items
        {
            lblrOnePayTotal0.Text = (GetOrderTotalPerItemShipping() + (3 * GetRecurringPayment())).ToString("N2");
        }
        else    //calculate single-pay subtotal for order with 3-pay items 
        {
            lblrOnePayTotal0.Text = (GetOrderTotalPerItemShipping() + (2 * GetRecurringPayment())).ToString("N2");
        }
        if (cbfourpay.Checked)
        {
            lblrPmtNumber.Text = "3";
            lblrPmtNumber0.Text = "3";
        }
        else
        {
            lblrPmtNumber.Text = "2";
            lblrPmtNumber0.Text = "2";
        }
        if (ddlPaymentType.SelectedValue == "EC")
        {
            lblECError.Visible = true;
        }
        else
        {
            lblECError.Visible = false;
        }
    }
    protected void btnInfoDone_Click(object sender, EventArgs e)
    {
        pnlInfo.Visible = false;
        pnlWizard.Visible = true;
        btnFAQ.Visible = true;
        btnViewOrder.Visible = true;
        btnSave.Visible = true;
    }
    protected void updateRecapTable()
    {
        buildOrder();
        BoundField desc = new BoundField();
        desc.DataField = "ProductDesc";
        desc.HeaderText = "Product Description";
        desc.HtmlEncode = false;
        BoundField Price = new BoundField();
        Price.DataField = "BaseRevenue";
        Price.HeaderText = "Per-Item Cost";
        Price.HtmlEncode = false;
        BoundField shipping = new BoundField();
        shipping.DataField = "SecondaryRevenue";
        shipping.HeaderText = "Shipping Cost Per Item";
        shipping.HtmlEncode = false;
        BoundField quantity = new BoundField();
        quantity.DataField = "Quantity";
        quantity.HeaderText = "Quantity";
        quantity.HtmlEncode = false;
        GridView1.Columns.Clear();
        GridView1.Columns.Add(desc);
        GridView1.Columns.Add(Price);
        GridView1.Columns.Add(shipping);
        GridView1.Columns.Add(quantity);
        GridView1.AutoGenerateColumns = false;
        GridView1.DataSource = ((DataAccess)Session["App"]).GetOrder();
        GridView1.DataBind();
    }
}

